package com.example.java8.feature_02;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class TestBase64 {

    public static void main(String[] args) throws UnsupportedEncodingException {
        // 获取解码器对象
        Base64.Decoder decoder = Base64.getDecoder();

        //获取编码器对象
        Base64.Encoder encoder = Base64.getEncoder();

        String text = "珠圆玉润";

        byte[] bytes = text.getBytes("UTF-8");

        // 编码
        String encode = encoder.encodeToString(bytes);
        System.out.println(encode);
        // 解码
        System.out.println(new String(decoder.decode(encode), "UTF-8"));
    }


}
